package com.qfedu.stussm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.stussm.dao.EmailDao;
import com.qfedu.stussm.dto.ScoreDto;
import com.qfedu.stussm.entity.Email;
import com.qfedu.stussm.service.intf.EmailService;
import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class EmailServiceImpl implements EmailService {
    @Autowired
    private EmailDao emailDao;
    @Override
    public int add(Email email) {
        return emailDao.add(email);
    }

    @Override
    public PageBeanVo selectAll(int page, int limit) {
        PageHelper.startPage(page, limit);
        PageInfo<Email> emailPageInfo = new PageInfo<>(emailDao.selectAll());
        return new PageBeanVo(emailPageInfo.getTotal(), emailPageInfo.getList());
    }

    @Override
    public R update(Email email) {
        if(emailDao.update(email) > 0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R del(int id) {
        if (emailDao.del(id) > 0) {
            return R.ok();
        } else {
            return R.fail();
        }
    }
}
